Use PIXEL_FORMAT_YUV420SP to fix phots purple/blue colour cast - #88
Draft
matt-t-needham wants to merge 2 commits into
Draft
Use PIXEL_FORMAT_YUV420SP to fix phots purple/blue colour cast#88matt-t-needham wants to merge 2 commits into
matt-t-needham wants to merge 2 commits into
Conversation
saki4510t's UVCCamera C lib has two YUYV conversion functions with similar names (see saki4510t#253): uvc_yuyv2yuv420SP — named YUV420SP, actually produces NV21 (V,U order) uvc_yuyv2iyuv420SP — named with 'i', actually produces NV12 (U,V order) Request PIXEL_FORMAT_YUV420SP (= 4) to get the NV21 data ordered correctly and correctly allocate colours.
matt-t-needham
marked this pull request as draft
March 24, 2026 21:07
Author
|
made with robot supervision, still testing and verifying, limited device availability |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Photos taken with takePicture() have a purple or blue colour cast. Videos are fine.
Expected cause
a bug already documented in saki4510t/UVCCamera#253:
takePicture()requests frames viasetFrameCallback(..., PIXEL_FORMAT_NV21). The native C library contains two YUYV conversions whose names and actual outputs are mismatcheduvc_yuyv2yuv420SPproduces NV21 (V,U chroma byte order)uvc_yuyv2iyuv420SPactually produces NV12 (U,V chroma byte order)Requesting
PIXEL_FORMAT_NV21 (= 5)routes to the function that produces NV12 data. Android'sYuvImage(data, ImageFormat.NV21)then inverts U and V shifting reds to blue/purple in the output. also reported in in saki4510t/UVCCamera#567.Fix
Change the pixel format constant from
PIXEL_FORMAT_NV21toPIXEL_FORMAT_YUV420SPin takePicture().PIXEL_FORMAT_YUV420SP (= 4)routes to the function that produces correctly-ordered NV21 data.saveTakenPictureToFile()is unchanged.Notes
If somebody hotfixed this already by post-processing photos to swap R/B channels they would see the inverse problem after this fix. Feels like it should be corrected, though?
This fix only affects the takePicture() path. The frame callback is removed immediately after capture and is never active during video recording, so I don't think it will affect that.